﻿using System;
using System.ComponentModel.DataAnnotations;
using System.Web;
using System.Web.DynamicData;
using System.Web.Routing;
using System.Collections.Generic;
using Niazi.CRM.Business.Model;
using System.Diagnostics;

namespace Mani.Common.UI
{
    public class Global : System.Web.HttpApplication
    {
        private static MetaModel s_CRMModel = new MetaModel();
        public static MetaModel CRMModel
        {
            get
            {
                return s_CRMModel;
            }
        }

        private static MetaModel s_SecurityModel = new MetaModel();
        public static MetaModel SecurityModel
        {
            get
            {
                return s_SecurityModel;
            }
        }


        public static void RegisterRoutes(RouteCollection routes)
        {
            CRMModel.RegisterContext(typeof(CRMModelContainer), new ContextConfiguration() { ScaffoldAllTables = false });
            SecurityModel.RegisterContext(typeof(Mani.Common.Security.SecurityEntities), new ContextConfiguration() { ScaffoldAllTables = false });

            routes.MapPageRoute("NewOrder", "Orders/Insert.aspx", "~/new_order.aspx", false, null, new RouteValueDictionary(new { table = "" }));

            routes.Add(new DynamicDataRoute("{table}/{action}.aspx")
            {
                Constraints = new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }),
                Model = CRMModel
            });

            routes.Add(new DynamicDataRoute("{table}/{action}.aspx")
            {
                Constraints = new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }),
                Model = SecurityModel
            });
        }

        void Application_Start(object sender, EventArgs e)
        {
            RegisterRoutes(RouteTable.Routes);
        }

    }
}
